<template>
    <div>
        <Card dis-hover >
            <h3>
                {{taskName}}
            </h3>
            <ButtonGroup slot="extra">
                <Button @click="approvalInfo" type="warning" style="background: #EF5350;" :loading="buttonloading" v-if="approval">
                    <Icon type="ios-bookmark" />
                    审批
                </Button>
                <Button @click="returnTo">
                    返回
                    <Icon type="ios-arrow-forward" />
                </Button>
            </ButtonGroup>
        </Card>
        <Row>
            <i-col span="24">
                <Card dis-hover style="margin: 10px;">
                    <Spin fix v-if="spinShow">
                        <Icon type="ios-loading" size=18 class="demo-spin-icon-load"></Icon>
                        <div>Loading</div>
                    </Spin>
                    <div :style="{height: bodyHeight + 'px', overflowY: 'auto', overflowX: 'hidden', }">
                        <Form ref="formCustom2" :model="infoData" :rules="ruleCustom2" label-position="top">
                            <Row :gutter="16">
                                <i-col span="18">
                                    <Row :gutter="16">
                                        <i-col span="24">
                                            <FormItem label="单位名称：">
                                                <Input v-model="infoData.orgName" type="text" :readonly="!ifEdit" v-if="!ifEdit"/>
                                                <orgDom ref="orgDom" @setOrgInfo="setOrgName" :orgInfo="{name: infoData.orgName}" :rootOrgId="rootOrgId" v-else></orgDom>
                                            </FormItem>
                                        </i-col>
                                    </Row>
                                    <Row :gutter="16">
                                        <i-col span="12">
                                            <FormItem label="姓名：">
                                                <Input v-model="infoData.userName" type="text" :readonly="!ifEdit" v-if="!ifEdit"/>
                                                <userDom ref="userDom" :ifUser=true  :singleChoice=true @setData = "setUserInfo" :selectData='{name: infoData.userName}' v-else></userDom>

                                            </FormItem>
                                        </i-col>
                                        <i-col span="12">
                                            <FormItem label="性别：" prop="gender">
                                                <Select v-model="infoData.gender" :disabled="!ifEdit">
                                                    <Option v-for="(item, index) in genderList" :value="item.id" :key="index">{{item.label}}</Option>
                                                </Select>
                                            </FormItem>
                                        </i-col>
                                    </Row>
                                    <Row :gutter="16">
                                        <i-col span="12">
                                            <FormItem label="政治面貌：" prop="politicalAffiliation">
                                                <Select v-model="infoData.politicalAffiliation" :disabled="!ifEdit">
                                                    <Option v-for="(item, index) in politicalAffiliationList" :value="item.codingCodeId" :key="index">{{item.codingName}}</Option>
                                                </Select>
                                            </FormItem>
                                        </i-col>
                                        <i-col span="12">
                                            <FormItem label="出生年月：" prop="birthday" >
                                                <DatePicker v-model="infoData.birthday" type="date" placeholder="请选择出生年月" style="width: 100%" :readonly="!ifEdit"></DatePicker>
                                            </FormItem>
                                        </i-col>
                                    </Row>
                                    <Row :gutter="16">
                                        <i-col span="12">
                                            <FormItem label="手机号码：" prop="phoneNumber">
                                                <Input type="text" v-model="infoData.phoneNumber" :readonly="!ifEdit"/>
                                            </FormItem>
                                        </i-col>
                                        <i-col span="12">
                                            <FormItem label="学历：" prop="education">
                                                <Select v-model="infoData.education" :disabled="!ifEdit">
                                                    <Option v-for="(item, index) in educationList" :value="item.codingCodeId" :key="index">{{item.codingName}}</Option>
                                                </Select>
                                            </FormItem>
                                        </i-col>
                                    </Row>
                                </i-col>
                                <i-col span="6" align="center">
                                    <Upload style="display: inline-block;width:58px;" v-show="fileList.length == 0"
                                            multiple
                                            ref="photoUpload"
                                            type="drag"
                                            name="files"
                                            :show-upload-list="false"
                                            :format="['jpg','jpeg','png']"
                                            :before-upload="beforeUpload"
                                            :action="fileUrl">
                                        <div style="width: 58px;height:58px;line-height: 58px;">
                                            <Icon type="ios-camera" size="20"></Icon>
                                        </div>
                                    </Upload>

                                    <div class="demo-upload-list"  v-for="(item, index) in fileList" :key="index">
                                        <img :src="item.picture" style="width:168px; height:210px"/>
                                        <div class="demo-upload-list-cover">
                                            <Icon type="ios-eye-outline" @click.native="viewFile(item.picture)"></Icon>
                                            <Icon type="ios-trash-outline" @click.native="removeFile(item)"  v-if="ifEdit"></Icon>
                                        </div>
                                    </div>
                                </i-col>
                            </Row>

                            <Row :gutter="16">
                                <i-col span="12">
                                    <FormItem label="专业：" prop="major">
                                        <Input type="text" v-model="infoData.major" placeholder="请输入专业" :readonly="!ifEdit"/>
                                    </FormItem>
                                </i-col>
                                <i-col span="12">
                                    <FormItem label="现职务（岗位）：" prop="currentPosition">
                                        <Input type="text" v-model="infoData.currentPosition" placeholder="请输入现职务（岗位）" :readonly="!ifEdit"/>
                                    </FormItem>
                                </i-col>
                            </Row>
                            <Row :gutter="16">
                                <i-col span="12">
                                    <FormItem label="工作年限：" prop="workYear">
                                        <Input type="number" v-model="infoData.workYear" placeholder="请输入工作年限" :readonly="!ifEdit"/>
                                    </FormItem>
                                </i-col>

                                <i-col span="12">
                                    <FormItem label="现职务（岗位）工作年限：" prop="currentPositionWorkYear">
                                        <Input type="number" v-model="infoData.currentPositionWorkYear" placeholder="现职务（岗位）工作年限" :readonly="!ifEdit"/>
                                    </FormItem>
                                </i-col>
                            </Row>
                            <Row>
                                <i-col span="12">
                                    <FormItem label="与安全生产管理相关的工作年限：" prop="relevantWorkYear" >
                                        <Input type="number" v-model="infoData.relevantWorkYear" placeholder="请输入与安全生产管理相关的工作年限" :readonly="!ifEdit"/>
                                    </FormItem>
                                </i-col>
                            </Row>
                            <Row :gutter="16">
                                <i-col span="24">
                                    <FormItem label="任职资格：" prop="qualification">
                                        <CheckboxGroup v-if="ifEdit" v-model="infoData.qualificationCheck" @on-change="changeQualification"><Checkbox v-for="item in qualificationList" :label="item.text"></Checkbox></CheckboxGroup>
                                        <Input v-model="infoData.qualification" placeholder="请输入任职资格" :readonly="!ifEdit"/>
                                    </FormItem>
                                </i-col>
                            </Row>
                            <Row :gutter="16">
                                <i-col span="24">
                                    <FormItem label="任职资格附件上传：">
                                        <Upload v-if="ifEdit"
                                                multiple
                                                ref="qualificationUpload"
                                                type="drag"
                                                name="files"
                                                :show-upload-list="false"
                                                :before-upload="beforeUpload4"
                                                :action="fileUrl2">
                                            <div style="padding: 20px 0">
                                                <Icon type="ios-cloud-upload" size="52" style="color: #3399ff"></Icon>
                                                <p>请上传任职资格附件</p>
                                            </div>
                                        </Upload>
                                        <div v-show="fileList2.length>0" v-for="item in fileList2" :key='item' style="margin: 3px">
                                            <a @click="downloadFile(item)">{{ item.fileName }} {{ item.name }}</a>
                                            <Button type="text" icon="md-trash" @click="remove2(item)" v-if="ifEdit"
                                                    style="margin-left: 5px;margin-bottom: 3px"/>
                                        </div>
                                    </FormItem>
                                </i-col>
                            </Row>

                            <Row :gutter="16">
                                <i-col span="24">
                                    <FormItem label="工作经历：" prop="workExperience">
                                        <Input v-model="infoData.workExperience" type="textarea" :rows="4" placeholder="请输入工作经历" :readonly="!ifEdit"/>
                                    </FormItem>
                                </i-col>
                            </Row>
                            <Row :gutter="16">
                                <i-col span="24">
                                    <FormItem label="工作经历附件上传：">
                                        <Upload v-if="ifEdit"
                                                multiple
                                                ref="workExperienceUpload"
                                                type="drag"
                                                name="files"
                                                :show-upload-list="false"
                                                :before-upload="beforeUpload3"
                                                :action="fileUrl3">
                                            <div style="padding: 20px 0">
                                                <Icon type="ios-cloud-upload" size="52" style="color: #3399ff"></Icon>
                                                <p>请上传工作经历附件</p>
                                            </div>
                                        </Upload>
                                        <div v-show="fileList3.length>0" v-for="item in fileList3" :key='item' style="margin: 3px">
                                            <a @click="downloadFile(item)">{{ item.fileName }} {{ item.name }}</a>
                                            <Button type="text" icon="md-trash" @click="remove3(item)" v-if="ifEdit"
                                                    style="margin-left: 5px;margin-bottom: 3px"/>
                                        </div>
                                    </FormItem>
                                </i-col>
                            </Row>
                        </Form>
                        <Divider orientation="left" v-if="approval">操作信息</Divider>
                        <Form ref="formCustom" :model="formData" :rules="ruleCustom" label-position="top">
                            <Row :gutter="16" v-if="ifSealFile">
                                <i-col span="24">
                                    <FormItem label="请上传盖章推荐表：" prop="seal">
                                        <Upload
                                                multiple
                                                ref="upload2"
                                                type="drag"
                                                name="files"
                                                :show-upload-list="false"
                                                :before-upload="beforeUpload2"
                                                :action="fileUrl">
                                            <div style="padding: 20px 0">
                                                <Icon type="ios-cloud-upload" size="52" style="color: #F27874"></Icon>
                                                <p><span style="color: red">*</span>&nbsp;请上传盖章推荐表</p>
                                            </div>
                                        </Upload>
                                        <div v-show="sealFile.length>0" v-for="item in sealFile" :key='item' style="margin: 3px">
                                            <a @click="downloadFile(item)">{{ item.fileName }} {{ item.name }}</a>
                                            <Button type="text" icon="md-trash" @click="remove1(item)"
                                                    style="margin-left: 5px;margin-bottom: 3px"/>
                                        </div>
                                    </FormItem>
                                </i-col>
                            </Row>
                            <Row :gutter="16">
                                <i-col span="8" v-if="ifRoute">
                                    <FormItem label="审批意见：" prop="route">
                                        <Select filterable v-model="formData.route" @on-change="changeRoute">
                                            <Option v-for="item in routeList" :value="item.id" :key="item.id">{{ item.name }}</Option>
                                        </Select>
                                    </FormItem>
                                </i-col>
                                <i-col span="8" v-if="ifqualifications">
                                    <FormItem label="审批意见：" prop="qualifications">
                                        <Select filterable v-model="formData.qualifications"  @on-change="changeQualifications">
                                            <Option v-for="item in qualificationsList" :value="item.id" :key="item.id">{{ item.label }}</Option>
                                        </Select>
                                    </FormItem>
                                </i-col>
                                <i-col span="8" v-if="ifTwoLevelCompanyLeader">
                                    <FormItem label="二级集团领导：" prop="dynamicAudits">
                                        <Select v-model="formData.dynamicAudits">
                                            <Option v-for="(item, index) in leaderList" :value="item.userId" :key="index">{{item.userName}}
                                                <span style="float:right;color:#ccc">{{item.orgName}} （{{item.positionName }}）</span>
                                            </Option>
                                        </Select>
                                    </FormItem>
                                </i-col>
                                <i-col span="8" v-if="ifGroupLeader">
                                    <FormItem label="集团领导：" prop="dynamicAudits">
                                        <Select v-model="formData.dynamicAudits">
                                            <Option v-for="(item, index) in leaderList" :value="item.userId" :key="index">{{item.userName}}
                                                <span style="float:right;color:#ccc">{{item.orgName}} （{{item.positionName }}）</span>
                                            </Option>
                                        </Select>
                                    </FormItem>
                                </i-col>
                            </Row>
                            <Row :gutter="16" v-if="approval">
                                <i-col span="8">
                                    <FormItem label="操作人：">
                                        <Input v-model="formData.userName" readonly/>
                                    </FormItem>
                                </i-col>
                                <i-col span="8">
                                    <FormItem label="操作时间：">
                                        <Input v-model="formData.createDateStr" readonly/>
                                    </FormItem>
                                </i-col>
                            </Row>
                            <Row :gutter="16" v-if="approval">
                                <i-col span="24">
                                    <FormItem label="说明：" prop="opinion">
                                        <Input type="textarea" v-model="formData.opinion"/>
                                    </FormItem>
                                </i-col>
                            </Row>
                        </Form>
                    </div>
                </Card>
            </i-col>
        </Row>
        <Modal title="附件查看" v-model="visible">
            <img :src="fileImgSrc" style="width: 100%">
            <div slot="footer" >
                <Button @click="visible=false" class="ivu-btn-save">关闭</Button>
            </div>
        </Modal>

    </div>
</template>

<script>

    import {Api} from '../../../api'
    import {sessionStorage} from '@/common/cacheUtils.js';
    import orgDom from "@/components/input-org.vue";
    import userDom from "@/components/input-user.vue";

    export default {
        name: "securityDirectorForm",
        components:{
            orgDom,
            userDom
        },
        data(){
            return{
                rootOrgId: sessionStorage('userId').getObject('userId').companyId,
                visible: false,
                fileImgSrc: '',
                fileUrl: '',
                fileUrl2: '',
                fileUrl3: '',
                taskName: '',
                buttonloading: false,
                approval: false,
                spinShow: false,
                bodyHeight: '',
                formData:{},
                ruleCustom: {
                    route: [
                        {
                            required: true,
                            message: '  ',
                            trigger: 'blur,change'
                        }
                    ],
                    qualifications: [
                        {
                            required: true,
                            message: '  ',
                            trigger: 'blur,change'
                        }
                    ],
                    dynamicAudits: [
                        {
                            required: true,
                            message: '  ',
                            trigger: 'blur,change'
                        }
                    ],
                },
                infoData: {},
                genderList: [
                    {
                        id: '男',
                        label: '男'
                    },
                    {
                        id: '女',
                        label: '女'
                    }
                ],
                qualificationsList:[
                    {
                        id: '1',
                        label: '符合'
                    },
                    {
                        id: '3',
                        label: '视同符合'
                    },
                    {
                        id: '4',
                        label: '不符合'
                    },
                    {
                        id: '6',
                        label: '信息需完善'
                    },
                ],
                politicalAffiliationList: [],
                educationList: [],
                userInfo: sessionStorage('userId').getObject('userId'),
                taskInfo: {},
                bodyHeight: '',
                ifRoute: false,
                ifEdit: false,
                ifSealFile: false,
                ifTwoLevelCompanyLeader: false,
                ifGroupLeader: false,
                ifqualifications: false,
                variables: {},
                routeList: [
                    {
                        id: '1',
                        name: '合格'
                    },
                    {
                        id: '2',
                        name: '不合格'
                    }
                ],
                ruleCustom2: {
                    orgName: [
                        {
                            required: true,
                            message: '  ',
                            trigger: 'blur,change'
                        }
                    ],
                    gender: [
                        {
                            required: true,
                            message: '  ',
                            trigger: 'blur,change'
                        }
                    ],
                    politicalAffiliation: [
                        {
                            required: true,
                            message: '  ',
                            trigger: 'blur,change'
                        }
                    ],
                    birthday: [
                        {
                            required: true,
                            message: '  ',
                            trigger: 'blur,change',
                            type: 'date'
                        }
                    ],
                    education: [
                        {
                            required: true,
                            message: '  ',
                            trigger: 'blur,change'
                        }
                    ],
                    major: [
                        {
                            required: true,
                            message: '  ',
                            trigger: 'blur,change'
                        }
                    ],
                    currentPosition: [
                        {
                            required: true,
                            message: '  ',
                            trigger: 'blur,change'
                        }
                    ],
                    workYear: [
                        {
                            required: true,
                            message: '  ',
                            trigger: 'blur,change',
                        }
                    ],
                    relevantWorkYear: [
                        {
                            required: true,
                            message: '  ',
                            trigger: 'blur,change',
                        }
                    ],
                    currentPositionWorkYear: [
                        {
                            required: true,
                            message: '  ',
                            trigger: 'blur,change',
                        }
                    ],
                    qualification: [
                        {
                            required: true,
                            message: '  ',
                            trigger: 'blur,change'
                        }
                    ],
                    workExperience: [
                        {
                            required: true,
                            message: '  ',
                            trigger: 'blur,change'
                        }
                    ],
                    phoneNumber: [
                        {
                            validator: (rule, value, callback) => {
                                if (!(/^1[3456789]\d{9}$/.test(this.infoData.phoneNumber))) {
                                    callback(' ');
                                } else {
                                    callback()
                                }
                            },
                            required: true,
                            trigger: 'blur'
                        }
                    ]
                },
                sealFile: [],
                fileList: [],
                leaderList: [],
                fileList2: [],
                fileList3: [],
                qualificationList: [
                    {
                        text: '机电工程师'
                    },
                    {
                        text: '土建工程师'
                    },
                    {
                        text: '安全工程师'
                    },
                ]
            }
        },
        mounted(){
            this.bodyHeight = window.innerHeight - 175;
            this.taskName = this.$route.query.taskName;
            this.taskInfo = this.$route.query;
            if(this.taskInfo.status == 'done' || this.taskInfo.status == 'self') this.approval = false; else this.approval = true;
            this.selectCodingSort();
            this.query();
        },
        methods: {
            selectCodingSort(){
                this.$http.get(Api.queryCodeDetailBySortId + '/1000001031', {params: {}}).then((res) => {
                    this.politicalAffiliationList = res.data.data;
                });
                this.$http.get(Api.queryCodeDetailBySortId + '/1000001032', {params: {}}).then((res) => {
                    this.educationList = res.data.data;
                });
            },
            query(){
                this.$http.get(Api.securityDirectorInfo + '/'+ this.taskInfo.workId ).then(function(response) {
                    if(response.data.status == 200) {
                        this.infoData = response.data.data;
                        if(this.infoData.qualification != undefined && this.infoData.qualification != null)
                            this.infoData.qualificationCheck = this.infoData.qualification.split("、");
                        if(this.taskInfo.status == 'done' || this.taskInfo.status == 'self')
                            this.spinShow = false;
                        else
                            this.queryFormList();
                    }
                });
                this.$http.get(Api.uploadPTWFiles   + '/' + this.taskInfo.workId + '/files/picture', {
                    params: {field: 'photo'},
                }).then((res) => {
                    if(res.data.data!=undefined){ this.fileList = res.data.data; }
                });
                this.$http.get(Api.uploadPTWFiles   + '/' + this.taskInfo.workId + '/files/guideFile').then((res) => {
                    if(res.data.data!=undefined){
                        res.data.data.forEach(item=>{
                            if(item.field == 'qualification'){
                                this.fileList2.push(item);
                            }else if(item.field == 'workExperience'){
                                this.fileList3.push(item);
                            }
                        })
                    }
                });
            },
            queryFormList(){
                this.$http.get(Api.getProcinstForm + '/'+ this.taskInfo.taskId).then(function(response){
                    if(response.data.formList.length!=0){
                        response.data.formList.map((i)=>{
                            if(i.id == 'route') this.ifRoute = true;
                            else if(i.id == 'edit'){
                                this.ifEdit = true;
                                this.fileUrl = Api.uploadPTWFiles  + '/' + this.infoData.id + '/files/picture/photo';
                                this.fileUrl2 = Api.uploadPTWFiles  + '/' + this.infoData.id + '/files/guideFile/qualification';
                                this.fileUrl3 = Api.uploadPTWFiles  + '/' + this.infoData.id + '/files/guideFile/workExperience';

                                this.$http.get(this.fileUrl, {
                                    params: {},
                                }).then((res) => {
                                    if(res.data.data!=undefined){ this.photoFile = res.data.data; }
                                })
                                setTimeout(() => {
                                    this.$refs.orgDom.setCurrentOrg();
                                    this.$refs.userDom.setCurrentInfo();
                                }, 300);
                            }
                            else if(i.id == 'sealFile'){
                                this.ifSealFile = true;
                                this.fileUrl = Api.uploadPTWFiles  + '/' + this.infoData.id + '/files/picture/seal';
                                this.$http.get(Api.uploadPTWFiles   + '/' + this.infoData.id + '/files/picture', {
                                    params: {field: 'seal'},
                                }).then((res) => {
                                    if(res.data.data!=undefined){ this.sealFile = res.data.data; }
                                })
                            }
                            else if(i.id == 'twoLevelCompanyLeader'){
                                this.ifTwoLevelCompanyLeader = true;
                                this.$http.get(Api.securityDirectorInfo + '/twoLevelOrg' , {params: {companyId: this.infoData.orgId}}).then((res) => {
                                    if(res.data.status == 200){
                                        if(res.data.data != null){
                                            this.queryLeader(res.data.data.orgId, res.data.data.orgName);
                                        }else{
                                            this.leaderList.push({userId: '8ad810e24f39585c014f395aae380000', userName: '超级管理员'})
                                        }
                                    }
                                }).catch(e => {
                                    this.$Message.error("获取二级集团领导失败")
                                })
                            }
                            else if(i.id == 'groupLeader'){
                                // this.queryLeader('18000000');

                                this.$http.get(Api.apsgRoleUser, {
                                    params: {orgId: '18000013', roleId: 'a717444fca8b499ca0dc50f4510d525c'}
                                }).then(function(res){
                                    res.data.map((i)=>{
                                        this.leaderList.push({userId: i.verifyuserid, userName: i.userName, positionName: '环境与安全管理部' });
                                        this.leaderList.push({userId: '8ad810e24f39585c014f395aae380000', userName: '超级管理员', positionName: '环境与安全管理部' });
                                    })
                                }, function(res){
                                    this.$Message.error('请求失败');
                                });

                                // this.leaderList = [{userId: 'AE67EA42698C44DF974D63D13971C1A7', userName: '李春支', positionName: '环境与安全管理部'}]
                                this.ifGroupLeader = true;
                            }else if(i.id == 'qualifications'){
                                this.ifqualifications = true;
                            }
                        });
                        this.spinShow = false;
                    }else{
                        this.spinShow = false;
                    }
                    this.variables = response.data.variables;
                    this.formData = {
                        userName: this.userInfo.userName,
                        taskId: this.taskInfo.taskId,
                        createUserId: this.userInfo.userId,
                        createDateStr: this.formatDate(new Date(), 'yyyy-MM-dd'),
                        procinstId: this.taskInfo.procinstId,
                        route: 1
                    }
                })
            },
            approvalInfo(){
                if(this.ifSealFile){
                    this.sealFile.map((i)=>{
                        this.$refs.upload2.post(i);
                    });
                }
                if(this.ifEdit == true){
                    let v = this.saveInfo();
                    if(!v){
                        this.buttonloading = false;
                        return;
                    }
                }
                if(this.ifqualifications) this.saveInfo();
                this.$refs['formCustom'].validate((valid) => {
                    if(valid){
                        this.buttonloading = true;
                        this.$http.get(Api.taskComplete, {
                            params: this.formData
                        }).then(function(response){
                            if(response.data.status == 200){
                                this.$Message.success({content: '保存成功', duration: 4});
                                this.screenMessage();
                                this.returnTo();
                            }else{
                                this.$Message.error({ content: '保存失败', duration: 4});
                            }
                            this.buttonloading = false;
                        });
                    }else{
                        this.$Message.error({ content: '请填写完整！', duration: 4});
                    }
                });
            },
            saveInfo(){
                let v = true;

                if(this.fileList.length == 0){
                    this.$Notice.error({
                        title: '请上传一寸免冠照！'
                    });
                    return false;
                }
                if(this.infoData.qualification != '无' && this.fileList2.length == 0){
                    this.$Notice.error({
                        title: '请上传任职资格附件！'
                    });
                    return false;
                }
                this.$refs['formCustom2'].validate((valid) => {
                    if(valid){
                        this.fileList.map((i)=>{
                            if(i.keyID!=undefined){
                                this.$refs.photoUpload.post(i);
                            }
                        });

                        this.fileList2.map((i)=>{
                            if(i.operation=='add'){
                                this.$refs.qualificationUpload.post(i);
                            }
                        });
                        this.fileList3.map((i)=>{
                            if(i.operation=='add'){
                                this.$refs.workExperienceUpload.post(i);
                            }
                        });
                        this.$http.put(Api.securityDirectorInfo, this.infoData).then(function(response){
                            if(response.data.status != 200){
                                this.$Message.error({ content: response.data.msg, duration: 4 });
                            }
                        });
                    }else{
                        this.$Message.error({ content: '请填写完整！', duration: 4});
                        v = false;
                    }
                });
                return v;
            },
            setOrgName(data){
                this.infoData.orgId = data.orgId;
                this.infoData.orgName = data.orgName;
                this.rootOrgId = data.orgId;
            },
            setUserInfo(data){
                this.infoData.userId = data.userId;
                this.infoData.userName = data.userName;
                this.$http.get(Api.getSaStaffEnvinfo + data.userId, {params: {}}).then((res) => {
                    if(res.data.data != null){
                        this.$set(this.infoData, 'birthday', res.data.data.birthDate);
                        this.$set(this.infoData, 'phoneNumber', res.data.data.cellPhone);
                        this.$set(this.infoData, 'education', res.data.data.eduId);
                        this.$set(this.infoData, 'gender', res.data.data.genderId == 'M'? '男': '女');
                    }
                })
            },
            returnTo(){
                this.$router.go(-1);
            },
            changeRoute(id){
                if(this.taskName == '企业领导'){
                    if(id==1){
                        this.ifTwoLevelCompanyLeader = true;
                    }else{
                        this.ifTwoLevelCompanyLeader = false;
                    }
                }else if(this.taskName == '二级集团领导'){
                    if(id==1){
                        this.ifGroupLeader = true;
                    }else{
                        this.ifGroupLeader = false;

                    }
                }
            },
            beforeUpload (file) {
                if(file.type.indexOf("image") == -1){
                    this.$Notice.warning({
                        title: '请上传图片格式附件！',
                    });
                } else{
                    if(this.fileList.length != 0){
                        this.removeFile(this.fileList[0]);
                    }
                    let self = this;
                    let keyID = Math.random().toString().substr(2);
                    file['keyID'] = keyID;
                    let reader = new FileReader();
                    reader.readAsDataURL(file);
                    reader.onload = function(ev) { //文件读取成功完成时触发
                        file['picture'] = ev.target.result; //获得文件读取成功后的DataURL,也就是base64编码
                        self.fileList.push(file);
                    }
                }
                return false;
            },
            beforeUpload2(file){
                this.sealFile.push(file);
                return false;
            },
            beforeUpload4(file){
                file.operation = 'add';
                this.fileList2.push(file);
                return false;
            },
            beforeUpload3(file){
                file.operation = 'add';
                this.fileList3.push(file);
                return false;
            },
            viewFile(imgBase64){
                this.visible = true;
                this.fileImgSrc = imgBase64;
            },
            removeFile(file){
                if(file.keyID==undefined){
                    this.$http.delete(Api.uploadMongoFile + "/" + file.id).then((res) => {
                        this.fileList.splice(this.fileList.indexOf(file), 1);
                    }).catch(e => {
                        this.$Message.error("附件删除失败");
                    });
                }else{
                    this.fileList = this.fileList.filter(item => {
                        return item.keyID != file.keyID
                    })
                }
            },
            downloadFile(file) {
                let url = Api.uploadPTWFiles + '/file/' + file.id;
                this.$http.get(url, {
                    responseType: 'blob'      //告诉服务器我们需要的响应格式
                }).then((res) => {
                    const aLink = document.createElement("a");
                    let blob = new Blob([res.data], {
                        type: res.bodyBlob.type      //将会被放入到blob中的数组内容的MIME类型
                    });
                    aLink.href = URL.createObjectURL(blob)
                    aLink.download = file.fileName //标题
                    aLink.click()
                    document.body.appendChild(aLink)
                })
            },
            remove1(file) {
                this.sealFile.splice(this.sealFile.indexOf(file), 1);
                if(file.id!=undefined){
                    let url = Api.uploadMongoFile + '/' + file.id;
                    this.$http.delete(url);
                }
            },
            formatDate(date, fmt) {
                if (/(y+)/.test(fmt)) {
                    fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
                }
                let o = {
                    'M+': date.getMonth() + 1,
                    'd+': date.getDate(),
                    'h+': date.getHours(),
                    'm+': date.getMinutes(),
                    's+': date.getSeconds()
                };
                for (let k in o) {
                    if (new RegExp(`(${k})`).test(fmt)) {
                        let str = o[k] + '';
                        fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? str : this.padLeftZero(str));
                    }
                }
                return fmt;
            },
            padLeftZero(str) {
                return ('00' + str).substr(str.length);
            },
            queryLeader(orgId, orgName ){
                this.$http.get(Api.securityDirectorInfo + '/leader' , {params: {companyId: orgId, orgName: orgName}}).then((res) => {
                    this.leaderList = res.data.data;
                    this.leaderList.push({userId: '8ad810e24f39585c014f395aae380000', userName: '超级管理员'})
                }).catch(e => {
                    this.$Message.error("数据获取失败")
                })
            },
            screenMessage(){
                if(this.taskName == '企业领导'){
                    if(this.formData.route == 1){
                        this.sendMessage(this.formData.dynamicAudits);
                    }else {
                        this.sendMessage(this.variables['reportUser']);
                    }
                }else if(this.taskName == '二级集团领导'){
                    if(this.formData.route == 1){
                        this.sendMessage(this.formData.dynamicAudits);
                    }else {
                        this.sendMessage(this.variables['reportUser']);
                    }
                }else if(this.taskName == '集团领导'){
                    this.sendMessage(this.variables['reportUser']);
                }
            },
            sendMessage(userId){
                let data = {userId: userId, content: "您有一条企业安全总监推荐表要审批，请登录安全环保信息平台进行审批" };
                this.$http.post(Api.sendMessage ,data);
            },
            changeQualifications(id){
                if(this.taskName == '二级集团领导'){
                    this.infoData.twoLevelOpinion = id == 1? '符合': id== '4'? '不符合': id=='3'? '视同符合': id=='6' ? '信息需完善': '';
                    if(id == 4||id == 6){
                        this.ifGroupLeader = false;
                    }else{
                        this.ifGroupLeader = true;
                    }
                }else if(this.taskName == '集团领导'){
                    this.infoData.groupOpinion = id == 1? '符合': id== '4'? '不符合': id=='3'? '视同符合': id=='6' ? '信息需完善': '';
                }
                this.formData.route = id;
            },
            remove2(file){
                this.fileList2.splice(this.fileList2.indexOf(file), 1);
                if(file.id!=undefined){
                    let url = Api.uploadMongoFile + '/' + file.id;
                    this.$http.delete(url);
                }
            },
            remove3(file){
                this.fileList3.splice(this.fileList3.indexOf(file), 1);
                if(file.id!=undefined){
                    let url = Api.uploadMongoFile + '/' + file.id;
                    this.$http.delete(url);
                }
            },
            changeQualification(data){
                let title = '';
                this.infoData.qualificationCheck.map((i=>{
                    title += i + '、';
                }))
                if(title!= '') this.infoData.qualification = title.substring(0, title.length -1);
                else this.infoData.qualification = ''
            }
        }
    }
</script>

<style scoped>
    .demo-spin-icon-load{
        animation: ani-demo-spin 1s linear infinite;
    }
    .demo-upload-list{
        display: inline-block;
        width: 168px;
        height: 212px;
        text-align: center;
        line-height: 212px;
        border: 1px solid transparent;
        border-radius: 4px;
        overflow: hidden;
        background: #fff;
        position: relative;
        box-shadow: 0 1px 1px rgba(0,0,0,.2);
        margin-top:10px;
    }
    .demo-upload-list img{
        width: 100%;
        height: 100%;
    }
    .demo-upload-list-cover{
        display: none;
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        background: rgba(0,0,0,.6);
    }
    .demo-upload-list:hover .demo-upload-list-cover{
        display: block;
    }
    .demo-upload-list-cover i{
        color: #fff;
        font-size: 20px;
        cursor: pointer;
        margin: 0 2px;
    }
</style>
